home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
language
/
pcl_src.zoo
/
str-class.lsp
< prev
next >
Wrap
Lisp/Scheme
|
1992-07-29
|
15KB
|
344 lines
;;;-*-Mode:LISP; Package:PCL; Base:10; Syntax:Common-lisp -*-
;;;
;;; *************************************************************************
;;; Copyright (c) 1985, 1986, 1987, 1988, 1989, 1990 Xerox Corporation.
;;; All rights reserved.
;;;
;;; Use and copying of this software and preparation of derivative works
;;; based upon this software are permitted. Any distribution of this
;;; software or derivative works must comply with all applicable United
;;; States export control laws.
;;;
;;; This software is made available AS IS, and Xerox Corporation makes no
;;; warranty about the software, its performance or its conformity to any
;;; specification.
;;;
;;; Any person obtaining a copy of this software is requested to send their
;;; name and post office or electronic mail address to:
;;; CommonLoops Coordinator
;;; Xerox PARC
;;; 3333 Coyote Hill Rd.
;;; Palo Alto, CA 94304
;;; (or send Arpanet mail to CommonLoops-Coordinator.pa@Xerox.arpa)
;;;
;;; Suggestions, comments and requests for improvements are also welcome.
;;; *************************************************************************
;;;
(in-package 'pcl)
(defmethod initialize-internal-slot-functions :after
((slotd structure-effective-slot-definition))
(let ((name (slot-definition-name slotd)))
(initialize-internal-slot-reader-gfs name)
(initialize-internal-slot-writer-gfs name)
(initialize-internal-slot-boundp-gfs name)))
(defmethod slot-definition-allocation ((slotd structure-slot-definition))
:instance)
(defmethod class-prototype ((class structure-class))
(with-slots (prototype) class
(or prototype
(setq prototype (make-class-prototype class)))))
(defmethod make-class-prototype ((class structure-class))
(with-slots (wrapper defstruct-constructor) class
(if defstruct-constructor
(make-instance class)
(let* ((proto (%allocate-instance--class *empty-vector*)))
(shared-initialize proto T :check-initargs-legality-p NIL)
(setf (std-instance-wrapper proto) wrapper)
proto))))
(defmethod make-direct-slotd ((class structure-class)
&rest initargs
&key
(name (error "Slot needs a name."))
(conc-name (class-defstruct-conc-name class))
(defstruct-accessor-symbol () acc-sym-p)
&allow-other-keys)
(declare (ignore defstruct-accessor-symbol))
(declare (type symbol name)
(type simple-string conc-name))
(let ((initargs (list* :class class :allow-other-keys T initargs)))
(unless acc-sym-p
(setf initargs
(list* :defstruct-accessor-symbol
(intern (concatenate 'simple-string conc-name (symbol-name name))
(symbol-package (class-name class)))
initargs)))
(apply #'make-instance (direct-slot-definition-class class initargs) initargs)))
(defun slot-definition-defstruct-slot-description (slot)
(let ((type (slot-definition-type slot)))
`(,(slot-definition-name slot) ,(slot-definition-initform slot)
,@(unless (eq type t) `(:type ,type)))))
(defmethod shared-initialize :after
((class structure-class)
slot-names
&key (direct-superclasses nil direct-superclasses-p)
(direct-slots nil direct-slots-p)
direct-default-initargs
(predicate-name nil predicate-name-p))
(declare (ignore slot-names direct-default-initargs))
(let* ((name (class-name class))
(from-defclass-p (slot-value class 'from-defclass-p))
(defstruct-form (defstruct-form name))
(conc-name
(or (if defstruct-form (defstruct-form-conc-name defstruct-form))
(slot-value class 'defstruct-conc-name)
(format nil #-excl "~s structure class "
#+excl "~s_STRUCTURE.CLASS_"
name)))
(defstruct-predicate
(if defstruct-form (defstruct-form-predicate-name defstruct-form)))
(pred-name ;; Predicate name for class
(or (if predicate-name-p (car predicate-name))
(if defstruct-form defstruct-predicate)
(slot-value class 'predicate-name)
(make-class-predicate-name name)))
(constructor
(or (if defstruct-form (defstruct-form-constructor defstruct-form))
(slot-value class 'defstruct-constructor)
(if from-defclass-p
(list (intern (format nil "~aconstructor" conc-name)
(symbol-package name))
())))))
(declare (type symbol name defstruct-predicate pred-name)
(type boolean from-defclass-p)
(type simple-string conc-name))
(if direct-superclasses-p
(setf (slot-value class 'direct-superclasses)
(or direct-superclasses
(setq direct-superclasses
(if (eq name 'structure-object)
nil
(list *the-class-structure-object*)))))
(setq direct-superclasses (slot-value class 'direct-superclasses)))
(setq direct-slots
(if direct-slots-p
(setf (slot-value class 'direct-slots)
(mapcar #'(lambda (pl)
(apply #'make-direct-slotd class
:conc-name conc-name pl))
direct-slots))
(slot-value class 'direct-slots)))
(when from-defclass-p
(do-defstruct-from-defclass
class direct-superclasses direct-slots conc-name pred-name constructor))
(compile-structure-class-internals
class direct-slots conc-name pred-name constructor)
(setf (slot-value class 'predicate-name) pred-name)
(setf (slot-value class 'defstruct-conc-name) conc-name)
(unless (extract-required-parameters (second constructor))
(setf (slot-value class 'defstruct-constructor) (car constructor)))
(when (and defstruct-predicate (not from-defclass-p))
(setf (symbol-function pred-name) (symbol-function defstruct-predicate)))
(unless (or from-defclass-p (slot-value class 'documentation))
(setf (slot-value class 'documentation)
(format nil "~S structure class made from Defstruct" name)))
(setf (find-class name) class)
(update-structure-class class direct-superclasses direct-slots)))
(defun update-structure-class (class direct-superclasses direct-slots)
(add-direct-subclasses class direct-superclasses)
(let ((cpl (compute-class-precedence-list class)))
(setf (slot-value class 'class-precedence-list) cpl)
(let* ((eslotds (compute-slots class))
(internal-slotds (mapcar #'slot-definition-internal-slotd eslotds)))
(setf (slot-value class 'slots) eslotds)
(setf (slot-value class 'internal-slotds) internal-slotds)
(setf (slot-value class 'side-effect-internal-slotds) internal-slotds))
(if (slot-value class 'wrapper)
(setf (wrapper-class-precedence-list (slot-value class 'wrapper)) cpl)
(progn
(setf (slot-value class 'finalized-p) T)
(setf (slot-value class 'wrapper) (make-wrapper class))))
(unless (slot-boundp class 'prototype)
(setf (slot-value class 'prototype) nil))
(setf (slot-value class 'default-initargs) nil))
(add-slot-accessors class direct-slots))
(defmethod do-defstruct-from-defclass ((class structure-class)
direct-superclasses direct-slots
conc-name predicate constructor)
(declare (type simple-string conc-name))
(let* ((name (class-name class))
(original-defstruct-form
`(original-defstruct
(,name
,@(when direct-superclasses
`((:include ,(class-name (car direct-superclasses)))))
(:print-function print-std-instance)
(:predicate ,predi